package com.anxin.act.utils;

/**
 * 查询sql工具类
 * @author: liuxiangyu
 * @date: 2020/3/30 18:30
 */
public class ActSqlUtils {

    private static final String TODO_SQL = "SELECT DISTINCT RES.* FROM ACT_RU_TASK RES LEFT JOIN ACT_RU_IDENTITYLINK i ON i.task_id_ = RES.id_ WHERE (RES.assignee_ = #{userName} OR ( RES.Assignee_ IS NULL AND ( i.user_id_ = #{userName}))) AND SUSPENSION_STATE_ != '0' ORDER BY RES.CREATE_TIME_ DESC ";

    private static final String TODO_JOIN_SQL ="LEFT JOIN ACT_RU_VARIABLE title ON title.PROC_INST_ID_ = t.PROC_INST_ID_ AND title.NAME_ = 'title' LEFT JOIN ACT_RU_VARIABLE apply ON apply.PROC_INST_ID_ = t.PROC_INST_ID_ AND apply.NAME_ = 'applyUserId' ";

    /**
     * 拼接查询待办数据的sql
     * @param whereSql
     * @return
     */
    public static StringBuffer getTodoSql(StringBuffer whereSql){
        return new StringBuffer("select t.* from ( "+TODO_SQL+" ) t " +TODO_JOIN_SQL+" where 1=1").append(whereSql);
    }

    /**
     * 拼接查询待办数量的sql
     * @param whereSql
     * @return
     */
    public static StringBuffer getTodoCountSql(StringBuffer whereSql){
        return new StringBuffer("select count(1) from ( "+TODO_SQL+" ) t " +TODO_JOIN_SQL+" where 1=1").append(whereSql);
    }



}
